/**
 * Created by wang on 2017/4/5.
 */



 function  DateDiff(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式  
       var  aDate,  oDate1,  oDate2,  iDays  ;
       aDate  =  sDate1.split("-")  ;
       oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]);    //转换为12-18-2006格式  
       aDate  =  sDate2.split("-")  ;
       oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]) ; 
       iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)  ;  //把相差的毫秒数转换为天数  
       return  iDays  ;
}    
function DASearch(){
	function getFromTo() {
        var fromTo=$('#date_demo3').text();   
        fromTo=fromTo.replace(/\s*/g,'').split('至');
        return fromTo;
    }
    var from = getFromTo()[0];
    var to = getFromTo()[1];
	var l = DateDiff(from,to);
	
	
    var ary1 = new Array();//进水压力
    var ary2 = new Array();//出水压力
    var ary3 = new Array();//1#


    for (var i = 0 ;i<l;i++) {
    	if($("#forcing_type").val() == 1){
    		var a = "0.7"+Math.floor(Math.random()*10+1);
			var b = "0.7"+Math.floor(Math.random()*10+1);
			var c = "0.7"+Math.floor(Math.random()*10+1);
	
			ary1.push(a);
			ary2.push(b);
			ary3.push(c);
    	}
    	else if($("#forcing_type").val() == 2){
    		var a = "0.3"+Math.floor(Math.random()*10+1);
			var b = "0.3"+Math.floor(Math.random()*10+1);
			var c = "0.3"+Math.floor(Math.random()*10+1);
	
			ary1.push(a);
			ary2.push(b);
			ary3.push(c);
    	}


    }

   	  // var option = myChart10.getOption();
      option10.series[0].data = ary1;   
      option10.series[1].data = ary2; 
      option10.series[2].data = ary3; 
      
      option10.xAxis.data = getDateArry(l);
      myChart10.setOption(option10);  

}




//获取半个月的日期数组
function p(s) {
    return s < 10 ? '0' + s: s;
}

function getDateArry(l) {
	var datenow = new Date();
    var currentYear=datenow.getFullYear();
     

    var datearry = new Array();
    for (var i = 0;i<l;i++) {
    	var datelast = new Date(datenow.getTime() - 24*60*60*1000*i);
    	var currentMonth = datelast.getMonth()+1; 
    	var currentDate = datelast.getDate();
        var current = currentMonth+"-"+p(currentDate);
        datearry[i] = current;
    }
    datearry.reverse();
    return datearry;
}


var myChart10 = echarts.init(document.getElementById('model10'), 'macarons');


option10 = {
    title: {
        text: ''
    },
    tooltip: {
        trigger: 'axis'
    },
    color:['#13a0e9','#fff109','#a7d66d'],
    legend: {
        data:['实时','同比','环比'],
        show:false
    },
    grid: {
        left: '1%',
        right: '1%',
        bottom: '1%',
        containLabel: true
    },
    toolbox: {
    	show:false
    },
    xAxis : {
    	type: 'category',
        boundaryGap: false,
        data: ['',],
        show:false
    } 
    ,
    yAxis: {
        type: 'value',
        axisLabel: {
            show:true,
            formatter: '{value}'
        },
        axisTick:{
        	show:false
    	},
    	splitLine:{ 
    		lineStyle: {
		        color: '#13232b'
		    }
        },
    },
    series: [
        {
            name:'实时',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#13a0e9'
					}
            	}
            },
            data:[0.1,0.5,0.5,0.1,0.5,0.7,0.58,0.5,0.9,0.5,0.5,0.5,0.5,0.5,0.5,0.1,0.5,0.5,0.1,0.5,0.7,0.58,0.5,0.9,0.5,0.5,0.5,0.5,0.5,0.5,]
        },
        {
            name:'同比',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#fff109'
					}
            	}
            },
            
            data:[0.1,0.5,0.5,1,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.1,0.5,0.5,0.1,0.5,0.7,0.58,0.5,0.9,0.5,0.5,0.5,0.5,0.5,0.5,]
        },
        {
            name:'环比',
            type:'line',
            smooth:true,
            symbol: 'none',
            itemStyle:{
            	normal:{
            		lineStyle:{
						color:'#a7d66d'
					}
            	}
            },
            data:[0.1,1,1,1,1,1,1,0.5,1,1,0.8,1,1,1,1,0.1,0.5,0.5,0.1,0.5,0.7,0.58,0.5,0.9,0.7,0.6,0.5,0.8,0.9,0.5,]
        }


    ]
};


// myChart10.setOption(option10);
$(function () {
    if ($('.nav-sub-active').hasClass('query_day')) {
        $('.double_pick').show();
            $('.tool_date').hide()
    }
    $('.pick_time').click(function () {
        $(this).addClass('nav-sub-active').siblings('.pick_time').removeClass('nav-sub-active')
         if ($(this).hasClass("query_day")) {
            $('.double_pick').show();
            $('.tool_date').hide()
        }
        if ($(this).hasClass("query_month")) {
            $('.double_pick').hide();
            $('.tool_date').show()
        }
    })
})